#include "precomp.h"
#include "jreadwritelock.h"
#include "jreadwritelock_p.h"

// - class JReadWriteLock -

/**
 * @brief JReadWriteLock::JReadWriteLock
 */
JReadWriteLock::JReadWriteLock()
{
    d = new JReadWriteLockPrivate(new QReadWriteLock());
}

/**
 * @brief JReadWriteLock::JReadWriteLock
 * @param recursionMode
 */
JReadWriteLock::JReadWriteLock(JReadWriteLock::RecursionMode recursionMode)
{
    d = new JReadWriteLockPrivate(new QReadWriteLock((QReadWriteLock::RecursionMode)recursionMode));
}

/**
 * @brief JReadWriteLock::~JReadWriteLock
 */
JReadWriteLock::~JReadWriteLock()
{
    delete d;
}

/**
 * @brief JReadWriteLock::lockForRead
 */
void JReadWriteLock::lockForRead()
{
    d->base->lockForRead();
}

/**
 * @brief JReadWriteLock::tryLockForRead
 * @return
 */
bool JReadWriteLock::tryLockForRead()
{
    return d->base->tryLockForRead();
}

/**
 * @brief JReadWriteLock::tryLockForRead
 * @param timeout
 * @return
 */
bool JReadWriteLock::tryLockForRead(int timeout)
{
    return d->base->tryLockForRead(timeout);
}

/**
 * @brief JReadWriteLock::lockForWrite
 */
void JReadWriteLock::lockForWrite()
{
    d->base->lockForWrite();
}

/**
 * @brief JReadWriteLock::tryLockForWrite
 * @return
 */
bool JReadWriteLock::tryLockForWrite()
{
    return d->base->tryLockForWrite();
}

/**
 * @brief JReadWriteLock::tryLockForWrite
 * @param timeout
 * @return
 */
bool JReadWriteLock::tryLockForWrite(int timeout)
{
    return d->base->tryLockForWrite(timeout);
}

/**
 * @brief JReadWriteLock::unlock
 */
void JReadWriteLock::unlock()
{
    d->base->unlock();
}

/**
 * @brief JReadWriteLock::JReadWriteLock
 * @param base
 */
JReadWriteLock::JReadWriteLock(QReadWriteLock *base)
{
    d = new JReadWriteLockPrivate(base, true);
}

/**
 * @brief JReadWriteLock::base
 * @return
 */
QReadWriteLock *JReadWriteLock::base() const
{
    return d->base;
}

// - class JReadLock -

/**
 * @brief JReadLocker::JReadLocker
 * @param readWriteLocker
 */
JReadLocker::JReadLocker(JReadWriteLock *readWriteLocker)
{
    d = new JReadLockerPrivate(readWriteLocker);
}

/**
 * @brief JReadLocker::~JReadLocker
 */
JReadLocker::~JReadLocker()
{
    delete d;
}

/**
 * @brief JReadLocker::unlock
 */
void JReadLocker::unlock()
{
    d->base.unlock();
}

/**
 * @brief JReadLocker::relock
 */
void JReadLocker::relock()
{
    d->base.relock();
}

/**
 * @brief readWriteLock
 * @return
 */
JReadWriteLock *JReadLocker::readWriteLock() const
{
    return d->readWriteLock;
}

// - class JWriteLock -

/**
 * @brief JWriteLocker::JWriteLocker
 * @param readWriteLocker
 */
JWriteLocker::JWriteLocker(JReadWriteLock *readWriteLocker)
{
    d = new JWriteLockerPrivate(readWriteLocker);
}

/**
 * @brief JWriteLocker::~JWriteLocker
 */
JWriteLocker::~JWriteLocker()
{
    delete d;
}

/**
 * @brief JWriteLocker::unlock
 */
void JWriteLocker::unlock()
{
    d->base.unlock();
}

/**
 * @brief JWriteLocker::relock
 */
void JWriteLocker::relock()
{
    d->base.relock();
}

/**
 * @brief JWriteLocker
 * @return
 */
JReadWriteLock *JWriteLocker::readWriteLock() const
{
    return d->readWriteLock;
}

